<template>
	<view class="detail">
		<navL :navlist="navlist" v-if="leixing == 4" @chooseNav="chooseNav"></navL>
		<view class="detail_list" v-if="isShow">
			<view class="list_item" v-for="(item,index) in list" :key="index">
				<view class="left">
					<text class="title">{{item.remarks}}</text>
					<text class="time">{{item.add_time | ShortTime}}</text>
				</view>
				<view class="left">
					<text class="num">{{item.num}}</text>
					<text v-if="item.show_balance"
						style="font-size: 12px;color: #777;text-align: right;">{{item.balance}}</text>
				</view>
				<!-- <text class="num">{{item.num}}</text> -->
			</view>
		</view>
		<view class="noMore" v-if="!isShow">
			------- 没有更多了 -------
		</view>
	</view>
</template>

<script>
	import {
		FinanceList
	} from "@/api/user.js"
	import navL from "@/components/nav/nav.vue"
	export default {
		components: {
			navL
		},
		data() {
			return {
				isShow: false,
				navlist: ['绿色积分收益', 'YSB收益', '余额收益'],
				navTpye: [2, 3, 1],
				leixing: '',
				type: '',
				list: [],
				page: 1,
				isAdd: true
			}
		},
		onReachBottom() {
			if (this.isAdd) {
				this.page++
				this.FinanceList()
			}
		},
		onLoad(e) {
			if (e.type == 3) {
				this.type = 3
			}
			this.type = e.type
			this.leixing = e.leixing
			// if (e.leixing == 4 || e.leixing == 5) {
			// 	this.type = 2
			// }
			if (e.leixing == 4) {
				this.type = 2
			}
			uni.setNavigationBarTitle({
				title: e.title
			})
			this.FinanceList()
		},
		methods: {
			chooseNav(e) {
				this.type = this.navTpye[e]
				this.list = []
				this.page = 1
				this.FinanceList()
			},
			FinanceList() {
				FinanceList({
					leixing: this.leixing,
					type: this.type,
					page: this.page
				}).then(res => {

					if (res.data.finance.length > 0) {
						this.isShow = true
						this.isAdd = true
						this.list = this.list.concat(res.data.finance)
					} else {
						this.isAdd = false
						if (this.list.length == 0) {
							this.isShow = false
						}
					}
				})
			}
		}
	}
</script>
<style lang="scss">
	page {
		background: #0F172A;
	}


	.noMore {
		padding-top: 30px;
		text-align: center;
		color: #fff;
	}

	.list_item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 10px;
		background-color: #1E293B;
		width: 96%;
		margin: 0 auto;
		margin-top: 10px;
		box-sizing: border-box;
		border-radius: 8px;
		color: #fff;

		.list_item_box {
			width: 100%;
		}

		.left {
			display: flex;
			flex-direction: column;
			font-size: 14px;

			.title {
				color: #7989D5;
				font-weight: bold;
				font-size: 15px;
			}

			.time {
				font-weight: bold;
				font-size: 12px;
				margin-top: 8px;
			}
		}

		.num {
			font-size: 14px;
			margin-top: 5px;
			display: flex;
			justify-content: space-between;
		}

		.tips {
			font-weight: bold;
		}
	}
</style>